home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Browsers, Managers & Extensions / Firefox Backup Extension 6.0.3 / chrome / febe.jar / content / febeOptions.js < prev    next >
Text File  |  2008-08-11  |  15KB  |  411 lines

  1. // author: Chuck Baker
  2. // contact: febe@customsoftwareconsult.com
  3. // Version 6.0
  4.     
  5.     window.addEventListener("load",febeBuProfileCheck,true);
  6.  
  7. function febeBuSelectAll(bool) {
  8.     var box = document.getElementById("buItems");
  9.     var checkboxes = box.getElementsByTagName("checkbox");
  10.     for(i=0; i<checkboxes.length; i++){
  11.         if(!checkboxes[i].disabled){
  12.             checkboxes[i].setAttribute("checked",bool);
  13.             var id = checkboxes[i].id;    // The ID is the same as the preference name.  Clever, eh?
  14.             var prefname = id.replace(/_/g,".");
  15.             febePrefs.setBoolPref(prefname,bool);
  16.         }//if
  17.     }//for
  18.     febeBuProfileCheck();
  19.     return true;
  20. }//febeBuSelectAll()
  21.  
  22. function febeBuProfileCheck(){
  23.     febeSetMsgs();
  24.     try{      
  25.         var buType = febePrefs.getCharPref("extensions.febe.buType");
  26.  
  27.         if(buType == "profile"){  // Disable options if profile backup is checked
  28.             document.getElementById("buExtensions_id").setAttribute("disabled",true);
  29.             document.getElementById("buThemes_id").setAttribute("disabled",true);
  30.             document.getElementById("additionalItemsID").setAttribute("disabled",true);
  31.         } else {
  32.             document.getElementById("buExtensions_id").setAttribute("disabled",false);
  33.             document.getElementById("buThemes_id").setAttribute("disabled",false);
  34.             document.getElementById("additionalItemsID").setAttribute("disabled",false);
  35.             febeOptionsCheck();
  36.         }//if
  37.     }catch(e){;}
  38.     window.removeEventListener("load",febeBuProfileCheck,true);
  39.     return true;
  40. }//febeBuProfileCheck()    
  41.  
  42. function febeSelExt(){
  43.   // Select extensions to backup
  44.     var w = "chrome://febe/content/febeSelExt.xul";
  45.     window.open(w, "FEBE Select Extensions", "chrome,alwaysRaised,centerscreen,resizable");
  46. }//febeSelExt()
  47.  
  48. function febeSelTheme(){
  49.   // Select extensions to backup
  50.     var w = "chrome://febe/content/febeSelTheme.xul";
  51.     window.open(w, "FEBE Select Themes", "chrome,alwaysRaised,centerscreen,resizable");
  52. }//febeSelTheme()
  53.  
  54. function febeSelBUDestDir(){
  55.   // Select backup destinaton directory
  56.     const nsIFilePicker = Ci.nsIFilePicker;
  57.     var fp = Cc["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
  58.     fp.init(window, febeMsg[5], nsIFilePicker.modeGetFolder);
  59.     fp.appendFilters(nsIFilePicker.filterAll | nsIFilePicker.filterText);
  60.  
  61.     // Set default directory to current backup directory
  62.     if(febePrefs.prefHasUserValue("extensions.febe.extBUdir")){
  63.         extBUdir = febeGetUnicharPref("extensions.febe.extBUdir");
  64.         if(extBUdir != ""){
  65.             var dd = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
  66.             dd.initWithPath(extBUdir);
  67.             fp.displayDirectory = dd;
  68.         }//if
  69.     }//if
  70.     var rv = fp.show();
  71.     if (rv == nsIFilePicker.returnOK){
  72.         rv = fp.file;
  73.         extBUdir = rv.path;
  74.         febeSetUnicharPref("extensions.febe.extBUdir", extBUdir);
  75.         document.getElementById("DestDirID").value = extBUdir;
  76.         var d = document.getElementById("DestDirID");
  77.         d.setAttribute("value",extBUdir);
  78.     }//if
  79.     febeCheckBuDestDir();
  80.     return true;
  81. }//febeSelBUDestDir()
  82.  
  83. function febeClearPrefs(){
  84.     var tmp = febeMsg[126]+"\n"+febeMsg[127]+"\n\n";
  85.     var style = "<style>color: red; font-weight: bold; font-size: 20px;</style>";
  86.     tmp += style+febeMsg[183]+"\n\n";
  87.     tmp += febeMsg[128]
  88.     var ok = febeConfirm(tmp);
  89.     if(!ok){return false;}
  90.     try {
  91.         var prefCount = {value:0}; 
  92.         var prefService = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService); 
  93.         var prefBranch = prefService.getBranch(null); 
  94.         var prefArray = prefBranch.getChildList("extensions.febe." , prefCount); 
  95.         var nsIPrefBranch = Ci.nsIPrefBranch;  
  96.         for (i = 0; i < prefCount.value; i++){
  97.             if(prefBranch.prefHasUserValue(prefArray[i])){prefBranch.clearUserPref(prefArray[i]);}
  98.         }
  99.         prefBranch.deleteBranch("extensions.febe.");
  100.         
  101.         // delete the destination file if it exists
  102.         var febeDataFile = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties).get("ProfD", Ci.nsIFile);
  103.         febeDataFile.append(FEBEDATAFILE);
  104.         if(febeDataFile.exists()){febeDataFile.remove(false);}
  105.     }catch (e) {
  106.         febeAlert(e);
  107.         return false;
  108.     }
  109.     var version = getFebeVersion();
  110.     var prefName = "extensions.febe.previousversion";
  111.     febePrefs.setCharPref(prefName,version);
  112.     febeAlert(febeMsg[129]);
  113.     febeRestartFx();
  114.     return true;
  115. }//febeClearPrefs()
  116.  
  117. function febeViewBuDir(){
  118.     var febeBuDestDir = document.getElementById("DestDirID").value;
  119.     febeOpenLink("file:///"+febeBuDestDir);
  120.     return true;
  121. }//febeViewBuDir()
  122.  
  123. function febeViewInstallDir(){
  124.     var febeInstallDir = document.getElementById("febeInstallPath").value;
  125.     febeOpenLink("file:///"+febeInstallDir);
  126.     return true;
  127. }//febeViewInstallDir()
  128.  
  129. function febeCheckBuDestDir(){
  130.     if(document.getElementById("DestDirID") && document.getElementById("DestDirID").value != ""){
  131.         document.getElementById("febeviewbudirbtnID").disabled = false;
  132.     }else{
  133.         document.getElementById("febeviewbudirbtnID").disabled = true;
  134.     }//if
  135.     return true;
  136. }//febeCheckBuDestDir()
  137.  
  138. function febeDisableOpts(){
  139.     try{    // Use a try blocks because statements refer to different preference windows which may not be loaded
  140.         document.getElementById("clearwarn_id").disabled = !document.getElementById("clearDestDir_id").checked;
  141.     }catch(e){;}
  142.     try{
  143.         document.getElementById("maxBuDirsLabelID").disabled = !document.getElementById("useTimestampedDir_id").checked;
  144.     }catch(e){;}
  145.     try{
  146.         document.getElementById("maxBuDirsID").disabled = !document.getElementById("useTimestampedDir_id").checked;
  147.     }catch(e){;}
  148.     try{
  149.         document.getElementById("febeTimestampFormatLabelID").disabled = !document.getElementById("useTimestampedDir_id").checked;
  150.     }catch(e){;}
  151.     try{
  152.         document.getElementById("febeTimestampFormat1ID").disabled = !document.getElementById("useTimestampedDir_id").checked;
  153.     }catch(e){;}
  154.     try{
  155.         document.getElementById("febeTimestampFormat2ID").disabled = !document.getElementById("useTimestampedDir_id").checked;
  156.     }catch(e){;}
  157.     try{
  158.         document.getElementById("febeclearbuinprogresstbtn").disabled = !febeBuInProgress();
  159.     }catch(e){;}
  160.     febePlatform = febeGetPlatform();
  161.     return true;
  162. }//febeDisableOpts()
  163.  
  164. function febeCloseButtonEtc(){
  165.     febeGetPlatform();
  166.     try{    // Use a try block because statements refer to different preference windows which may not be loaded
  167.       // Show close button for Mac OS X users because they don't get buttons for <prefwindow>
  168.       // Looks like Fx3 doesn't show for *nix either      
  169.         if(febePlatform == 2 || febePlatform == 3){
  170.             document.getElementById("febeMacAcceptBtn").hidden = false;
  171.         }//if
  172.         
  173.         // Set text direction
  174.         var textdir = document.getElementById("febeTextDir").value;
  175.         if(!textdir){textdir = "ltr";}
  176.         var prefName = "extensions.febe.orientation";
  177.         febePrefs.setCharPref(prefName,textdir);
  178.         
  179.       // Add event listeners
  180.         var d = document.getElementById("febeTimestampFormatID");
  181.         d.addEventListener("RadioStateChange", febeTimestampDirCheck, false);
  182.     }catch(e){;}
  183.     return true;
  184. }//febeCloseButtonEtc()
  185.     
  186. function febeOptionsCheck(){
  187.   // Enable/disable options
  188.     // Create pointer to profile directory
  189.     febeProfDir = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties).get("ProfD", Ci.nsIFile);
  190.     
  191.     var buType = febePrefs.getCharPref("extensions.febe.buType");
  192.     if(buType == "profile"){return true;}
  193.     
  194.     var tmp = "";   
  195.     // Check userChrome.css
  196.     var d = document.getElementById("extensions_febe_buUserChrome");
  197.     var profileDir = febeProfDir.clone();
  198.     profileDir.append("chrome");
  199.     profileDir.append("userChrome.css");
  200.     if(!profileDir.exists()){
  201.         if(d.checked == true){tmp += d.label + "\n";}
  202.         d.checked = false;
  203.         d.setAttribute("disabled",true);
  204.         var prefName = "extensions.febe.buUserChrome";
  205.         febePrefs.setBoolPref(prefName,false);
  206.     }else{
  207.         d.setAttribute("disabled",false);
  208.     }//if
  209.         
  210.     // Check cookies.txt
  211.     var d = document.getElementById("extensions_febe_buCookies");
  212.     var profileDir = febeProfDir.clone();
  213.     profileDir.append("cookies.sqlite");
  214.     if(!profileDir.exists()){
  215.         if(d.checked == true){tmp += d.label + "\n";}
  216.         d.checked = false;
  217.         d.setAttribute("disabled",true);
  218.         var prefName = "extensions.febe.buCookies";
  219.         febePrefs.setBoolPref(prefName,false);
  220.     }else{
  221.         d.setAttribute("disabled",false);
  222.     }//if
  223.     
  224.     // Check usernames/passwords
  225.     var d = document.getElementById("extensions_febe_buUserPwd");
  226.     var loginManager = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);    
  227.     var logins = loginManager.getAllLogins({});
  228.     if(logins.length < 1){
  229.         if(d.checked == true){tmp += d.label + "\n";}
  230.         d.checked = false;
  231.         d.setAttribute("disabled",true);
  232.         var prefName = "extensions.febe.buUserPwd";
  233.         febePrefs.setBoolPref(prefName,false);
  234.     }else{
  235.         d.setAttribute("disabled",false);
  236.     }//if
  237.         
  238.     // Check searchPlugins
  239.     var d = document.getElementById("extensions_febe_buSearchPlugins");
  240.     var profileDir = febeProfDir.clone();
  241.     profileDir.append("searchplugins");
  242.     if(!profileDir.exists()){
  243.         if(d.checked == true){tmp += d.label + "\n";}
  244.         d.checked = false;
  245.         d.setAttribute("disabled",true);
  246.         var prefName = "extensions.febe.buSearchPlugins";
  247.         febePrefs.setBoolPref(prefName,false);
  248.     }else{
  249.         d.setAttribute("disabled",false);
  250.     }//if
  251.     
  252.     // Check history.dat
  253.     var d = document.getElementById("extensions_febe_buBrowserHistory");
  254.     var historyService = Cc["@mozilla.org/browser/nav-history-service;1"].getService(Ci.nsINavHistoryService);
  255.     if(!historyService.hasHistoryEntries){
  256.         if(d.checked == true){tmp += d.label + "\n";}
  257.         d.checked = false;
  258.         d.setAttribute("disabled",true);
  259.         var prefName = "extensions.febe.buBrowserHistory";
  260.         febePrefs.setBoolPref(prefName,false);
  261.     }else{
  262.         d.setAttribute("disabled",false);
  263.     }//if
  264.     
  265.     // Check formhistory.dat
  266.     var d = document.getElementById("extensions_febe_buFormFillHistory");
  267.     var dbFile = febeProfDir.clone();
  268.     dbFile.append("formhistory.sqlite");
  269.  
  270.     var storageService = Cc["@mozilla.org/storage/service;1"].getService(Ci.mozIStorageService);
  271.     var db = storageService.openDatabase(dbFile);
  272.     var sQuery = "SELECT * FROM moz_formhistory";
  273.     var stmt = db.createStatement(sQuery);
  274.     if(!stmt.executeStep()){
  275.         if(d.checked == true){tmp += d.label + "\n";}
  276.         d.checked = false;
  277.         d.setAttribute("disabled",true);
  278.         var prefName = "extensions.febe.buFormFillHistory";
  279.         febePrefs.setBoolPref(prefName,false);
  280.     }else{
  281.         d.setAttribute("disabled",false);
  282.     }//if
  283.     
  284.     // Check permissions
  285.     var d = document.getElementById("extensions_febe_buPermissions");
  286.     var dbFile = febeProfDir.clone();
  287.     dbFile.append("permissions.sqlite");
  288.  
  289.     var storageService = Cc["@mozilla.org/storage/service;1"].getService(Ci.mozIStorageService);
  290.     var db = storageService.openDatabase(dbFile);
  291.     var sQuery = "SELECT * FROM moz_hosts";
  292.     var stmt = db.createStatement(sQuery);
  293.     if(!stmt.executeStep()){
  294.         if(d.checked == true){tmp += d.label + "\n";}
  295.         d.checked = false;
  296.         d.setAttribute("disabled",true);
  297.         var prefName = "extensions.febe.buPermissions";
  298.         febePrefs.setBoolPref(prefName,false);
  299.     }else{
  300.         d.setAttribute("disabled",false);
  301.     }//if
  302.     
  303.     // Check user-defined backups
  304.     var d = document.getElementById("extensions_febe_buUDBu");
  305.     if(febeUDBuInit() == false){
  306.         if(d.checked == true){tmp += d.label + "\n";}
  307.         d.checked = false;
  308.         d.setAttribute("disabled",true);
  309.         var prefName = "extensions.febe.buUDBu";
  310.         febePrefs.setBoolPref(prefName,false);
  311.     }else{
  312.         d.setAttribute("disabled",false);
  313.     }//if
  314.     
  315.     // Display message
  316.     if(febex == true){return;}    // Display msg only once
  317.     febex = true;
  318.     if(tmp.length != 0){
  319.         var style = "<style>color: red; font-weight: bold; font-size: 15px;</style>";
  320.         tmp = style+febeMsg[184]+"\n\n"+tmp;
  321.         febeAlert(tmp);
  322.     }//if
  323. }//febeOptionsCheck()
  324.  
  325. function febeProfileWizard(){
  326.     var wizard = "chrome://mozapps/content/profile/createProfileWizard.xul";
  327.     window.open(wizard, "FEBE Help", "chrome,alwaysRaised,centerscreen,resizable");
  328. }//febeProfileWizard()
  329.  
  330. function febeTimestampDirCheck(event){
  331.     var selected = document.getElementById("febeTimestampFormatID").selectedItem.value;
  332.     var current = febePrefs.getCharPref("extensions.febe.timestamp.format");
  333.     if(current == selected){return true;}
  334.     if(!febeGetBDD()){return false;}        // Get backup destination directory
  335.  
  336.     var tags = ["ISO8601","European"];
  337.     var masks = [/^FEBE \d\d\d\d \d\d\.\d\d \d\d\.\d\d\.\d\d$/,/^FEBE \d\d\d\d \d\d-\d\d \d\d\.\d\d\.\d\d$/];
  338.     var which = document.getElementById("febeTimestampFormatID").selectedIndex;
  339.     var mask = masks[which];
  340.     var dirArray = {};
  341.     var numDirsToRename = 0;
  342.     var buDirRoot = febeBuDesDir.clone();
  343.     var entries = buDirRoot.directoryEntries;
  344.     
  345.     // Count the number of directories that need to be renamed
  346.     while(entries.hasMoreElements()){
  347.         var entry = entries.getNext();
  348.         entry.QueryInterface(Ci.nsIFile);
  349.         var dirName = entry.leafName;
  350.         if(!entry.isDirectory()){continue;}
  351.         if(!dirName.match(mask)){continue;}
  352.         numDirsToRename++;
  353.         
  354.         dirArray[dirName] = febeNewDirName(which,dirName);
  355.     }//while
  356.     if(numDirsToRename == 0){return true;}
  357.     
  358.     var newformat,oldformat;
  359.     switch(which){
  360.         case 0:    
  361.             oldformat = tags[1];
  362.             newformat = tags[0];
  363.             break;
  364.         case 1:    
  365.             oldformat = tags[0];
  366.             newformat = tags[1];
  367.             break;
  368.     }//switch
  369.     var tmp = febeMsg[204].replace("%NUMDIR%",numDirsToRename);
  370.     tmp = tmp.replace("%FORMT%",oldformat)+"\n";
  371.     tmp += febeMsg[205].replace("%NEWFORMAT%",newformat)+"\n\n"+febeMsg[41];
  372.     tmp="<style>color: red; font-weight: bold; font-size: 20px;</style>"+tmp;
  373.     if(!febeConfirm(tmp)){
  374.         switch(which){ // Switch it back to where it was
  375.         case 0:    
  376.             document.getElementById("febeTimestampFormatID").selectedIndex = 1;
  377.             break;
  378.         case 1:    
  379.             document.getElementById("febeTimestampFormatID").selectedIndex = 0;
  380.             break;
  381.     }//switch
  382.         febePrefs.setCharPref("extensions.febe.timestamp.format",current);
  383.         febeAlert(febeMsg[206]);
  384.         return false;
  385.     }//if
  386.     
  387.     // Rename the directories
  388.     for(var i in dirArray){
  389.         var rnDir = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
  390.         rnDir.initWithPath(buDirRoot.path);
  391.         rnDir.append(i);
  392.  
  393.         var filespec = Cc["@mozilla.org/filespec;1"].createInstance(Ci.nsIFileSpec);
  394.         filespec.nativePath = rnDir.path;
  395.         
  396.         filespec.rename(dirArray[i]);
  397. //alert("Rename "+i+" to "+dirArray[i])
  398.  
  399.     }//for
  400.     tmp = febeMsg[207].replace("%NUMDIR%",numDirsToRename);
  401.     tmp = tmp.replace("%NEWFORMAT%",newformat);
  402.     febeAlert(tmp);
  403.     febePrefs.setCharPref("extensions.febe.timestamp.format",selected)
  404. }//febeTimestampDirCheck()
  405.  
  406. function febeClearBuInProgressFlag(){
  407.     febePrefs.setBoolPref("extensions.febe.backupInProgress",false);
  408.     document.getElementById("febeclearbuinprogresstbtn").disabled = true;
  409. }//febeClearBuInProgressFlag()
  410. //alert("febeOptions.js loaded");
  411.